package com.woshua.livedatabusmodel;

import android.arch.lifecycle.Observer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.woshua.livedatabusmodel.event.LiveDataBus;

public class TwoActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_two);

        final TextView tvContent=findViewById(R.id.tv_content);
        LiveDataBus.get().with("TwoActivity",HuaWei.class).observe(this, new Observer<HuaWei>() {
            @Override
            public void onChanged(@Nullable HuaWei huaWei) {
                tvContent.setText(huaWei.getName());
            }
        });
    }

    public void sendMsgClick(View view) {
        HuaWei huaWei=new HuaWei("华为","XHUA_WEI");
        LiveDataBus.get().post("TwoActivity",huaWei);
    }
}
